package com.xinxing.city.recovery.utils;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.xinxing.city.recovery.R;
import com.xinxing.city.recovery.interfaces.MyDialogListener;

import java.util.ArrayList;
import java.util.List;

public class DialogTest extends Dialog {
    private MyDialogListener mListener;
    private Context context;
    private String btn1Str;
    private String btn2Str;
    private String ARG_TITLE = "arg_title";
    private String ARG_CONTENT = "";
    private String edStr = null;
    public DialogTest(@NonNull Context context, int themeResId, String btn1, String btn2Str,String arg_title,String arg_content,String ed) {
        super(context, themeResId);
        this.context = context;
        this.btn1Str = btn1;
        this.btn2Str = btn2Str;
        this.ARG_CONTENT = arg_content;
        this.ARG_TITLE = arg_title;
        this.edStr = ed;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//去掉信息栏
        this.getWindow().setContentView(R.layout.custom_dialog);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.custom_dialog);
        Button button1 = findViewById(R.id.dialog_button_ok);
        if (btn1Str != null && !btn1Str.equals("")) {
            button1.setText(btn1Str);
            button1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (mListener != null)
                        mListener.onPositiveClick();
                }
            });
        } else {
            button1.setVisibility(View.GONE);
        }
        TextView dialog_title = findViewById(R.id.dialog_title);
        dialog_title.setText(ARG_TITLE);
        EditText inputE = findViewById(R.id.inputEditText);
        TextView dialog_message = findViewById(R.id.dialog_message);


        if (edStr != null) {
            inputE.setVisibility(View.VISIBLE);
            dialog_message.setVisibility(View.GONE);

        } else {
            inputE.setVisibility(View.GONE);
            dialog_message.setVisibility(View.VISIBLE);
            dialog_message.setText(ARG_CONTENT);
        }
        Button button2 = findViewById(R.id.dialog_button_cancel);
        if (btn2Str != null && !btn2Str.equals("")) {
            button2.setText(btn2Str);
            button2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (mListener != null)
                        mListener.onNegativeClick();
                }
            });
        } else {
            button2.setVisibility(View.GONE);
        }
    }

    public void setListener(MyDialogListener listener) {
        this.mListener = listener;
    }
}
